package org.example;

import org.example.cassell_client.service.BulletinServiceClient;
import org.example.cassell_client.service.UserServiceClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;

import java.util.function.Function;

@Configuration
public class FunctionTools {

    private static final Logger logger = LoggerFactory.getLogger(FunctionTools.class);
    @Autowired
    private UserServiceClient userServiceClient;
    @Autowired
    private BulletinServiceClient bulletinServiceClient;
    public record updatePassWord(String Email,String UserPassWord) {
    }

    public record userlist(){
    }
    public record getNacos(String serverName){
    }

    public record bulletinlist(){
    }
    public record bulletingetContent(Integer id){
    }
    @Bean
    @Description("用户修改密码")
    public Function<updatePassWord, String>  updatePassWord() {
        return request -> {
            userServiceClient.updatePassWord(request.Email,request.UserPassWord);
            return "修改密码成功"+request.UserPassWord;
        };
    }

    @Bean
    @Description("获取用户列表")
    public Function<userlist, String>  userlist() {
        return request -> {
            return "成功获取用户列表"+userServiceClient.userl();
        };
    }

    @Bean
    @Description("获取nacos状态")
    public Function<getNacos, String>  getNacos() {
        return request -> {
            return "成功获取用户列表"+NacosConfig.getStatus(request.serverName);
        };
    }
    @Bean
    @Description("获取公告列表")
    public Function<bulletinlist, String>  bulletinlist() {
        return request -> {
            return "成功获取公告列表"+bulletinServiceClient.bulletinl();
        };
    }
    @Bean
    @Description("获取公告内容")
    public Function<bulletingetContent, String>  bulletingetContent() {
        return request -> {
            return "成功获取公告内容"+bulletinServiceClient.getContent(request.id);
        };
    }
}
